import requests
from bs4 import BeautifulSoup
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0'
}
'''
解析豆瓣网站TOP250的电影名称
'''
map = {}
index = 0
for page in range(1, 11):
    resp = requests.get(f"https://movie.douban.com/top250?start={index}", headers=headers)

    soup = BeautifulSoup(resp.text, 'html.parser')

    all_div_class_hd = soup.findAll('div', attrs={'class': 'hd'})

    names = ""
    for class_hd in all_div_class_hd:
        hd_a = class_hd.find('a')
        # 得到电影名称
        movies_name = hd_a.find('span').string
        names += movies_name + "\n"
    index += 25
    map[page] = names

for key in map.keys():
    print(f'第【{key}】页：\n{map[key]}')
